package com.buymobile.components.page;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class PageTag extends TagSupport{
	
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -870228120180133597L;
	private Page page;
	
	private String url;

	
	
	@Override
	public int doStartTag() throws JspException {
		JspWriter out = pageContext.getOut();
		try {
			if(url.indexOf("?") == -1){
				url += "?temp=temp";
			}
			StringBuilder sb = new StringBuilder();
			if(page.getIndex() != 1)
				sb.append("<a href='").append(url).append("&pageIndex=").append(page.getPrePage()).append("'>上一页</a>");
			if(page.getIndex() != page.getPageCount())
				sb.append("<a href='").append(url).append("&pageIndex=").append(page.getNextPage()).append("'>下一页</a>");
			
			sb.append("当前第: ").append(page.getIndex()).append("页  共 : ").append(page.getPageCount()).append(" 页   总记录： ").append(page.getRowCount());
			
			out.write(sb.toString());
		} catch (IOException e) {
			throw new JspException(e);
		}
		return TagSupport.SKIP_BODY;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	

}
